


class Squick

  # tells you if nick is in the ops DB, NOT if he is an op in the channel.
  def isOp(nick)
    res = @db.execute("select * from ops where nick='#{nick}'")
    if(res.size == 0) then return false
    else return true end
  end

  # Clears out the old ops table in the db and repopulates it from
  # the ops XML file.
  def populateOpsDB(msg)
    return nil unless(msg.match(/!refresh_ops/))
    refresh 
    return "Ops list updated"
  end

  def refresh(names = nil)
    file = File.new("opManagementAddon/ops.xml")
    opsDoc = REXML::Document.new(file)
    file.close

    @db.execute("delete from ops")
    opsDoc.each_element("Ops/Op") do |op|
      @db.execute("insert into ops(nick) values('#{op.text}')")
    end

    return nil
  end

  def manageOpsJoin(nick)
    elevateToOp(nick) if(isOp(nick))
  end
end
